package com.huanyang.common;

import java.io.Serializable;

public class Result<T> implements Serializable {

    /**
     * 状态码
     */
    private int code;

    /**
     * 信息描述
     */
    private String message;

    /**
     * 结果集
     */
    private T data;

    public static<T> Result success(int code, String message) {
        Result<Object> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }
    public static<T> Result success(int code, String message, T data) {
        Result<Object> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static<T> Result fail(int code, String message) {
        Result<Object> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }
    public static<T> Result fail(int code, String message, T data) {
        Result<Object> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
